package com.moore.controller;

import com.moore.bean.Area;
import com.moore.dto.ResponseData;
import com.moore.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.moore.utils.Logger.toLog;

@Controller
@RequestMapping("/area")
public class AreaController {
    @Autowired
    private AreaService areaService;

    @RequestMapping("/add")
    @ResponseBody
    public ResponseData addArea(@RequestBody Area area){
        String province = area.getProvince();
        String city = area.getCity();
        String areaName = area.getName();
        String remarks = area.getRemarks();
        toLog("正在添加区域"+province+city+areaName);
        return areaService.addArea(province,city,areaName,remarks);
    }

    @RequestMapping("/province")
    @ResponseBody
    public ResponseData getProvince(){
        toLog("正在获取省份列表");
        return areaService.getProvince();
    }

    @RequestMapping("/city")
    @ResponseBody
    public ResponseData getCity(@RequestBody Area area){
        String province = area.getProvince();
        toLog("正在获取"+province+"的城市列表");
        return areaService.getCity(province);
    }

    @RequestMapping("/query")
    @ResponseBody
    public ResponseData queryArea(@RequestBody Area area){
        String province = area.getProvince();
        String city = area.getCity();
        String areaName = area.getName();
        int size = area.getSize();
        int curr = area.getCurr();
        toLog("正在查询"+province+city+areaName+"区域");
        return areaService.queryArea(province,city,areaName,size,curr);
    }

    @RequestMapping("/update")
    @ResponseBody
    public ResponseData updateArea(@RequestBody Area area){
        long id = area.getId();
        toLog("正在更新区域"+id);
        return areaService.updateArea(area);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData deleteArea(@RequestBody List<Area> areas){
        toLog("正在删除区域");
        return areaService.deleteArea(areas);
    }
}
